package com.example.blank700.intentreceiverinxml;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class IntentReceiverInXmlActivity extends AppCompatActivity {
    private Button myButton = null;
    //要被监听到的数据
    private final String nobody = "this.is.a.message";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent_receiver_in_xml);

        myButton = (Button) findViewById(R.id.myButton);
        myButton.setOnClickListener(new MyButtonListener());
    }

    class MyButtonListener implements OnClickListener {
        public void onClick(View v) {
            //实例化一个Intent对象
            Intent intent = new Intent(nobody);
            //在Intent对象中添加键值对
            intent.putExtra("testIntent", "700");
            //广播发送
            sendBroadcast(intent);
        }
    }
}
